<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%@ include file="../../header_inc.jsp"%> 
<script type="text/javascript">

	//所有的子窗体都需要有一个save函数，当点击弹出窗体的保存按钮时所进行的操作
	function btnSave_click() {
	
	var fun_ret;
		var file = $('#uploadFile')[0];
		var imagSize =  document.getElementById("uploadFile").files[0];
		if(imagSize != null && imagSize != "" && !isNull( imagSize )){
			imagSize = imagSize.size;
		}
		name = file.value;
		var pic = /.+(.JPEG|.jpeg|.JPG|.jpg|.GIF|.gif|.BMP|.bmp|.PNG|.png)$/;
		var end = name.substr(name.lastIndexOf("."));
		if (name != "" && name != null && end !=".jpg" && end !=".JPEG" && end !=".jpeg" &&end !=".JPG" && end !=".PNG" && end !=".png" ) {
			$.messager.alert("提示", " 您选择的不是图片文件，请重新选择！");
			return false;
		}else{
			if(imagSize > 2048000){
					$.messager.alert("错误提示", "图片需要限制在2000kb以内！");
			        return false;
			}
		}  
	 	var formData = new FormData($('#formModule')[0]);
	
		$.ajax(
				{
					url : '/shoeHouse/commodifyInfo/${method}', //server script to process data
					type : 'POST',
					data : formData,
					async: false,
					cache : false,
					contentType : false,
					processData : false,
					dataType:'json',//请求的数据类型
					xhr : function() { // custom xhr
						myXhr = $.ajaxSettings.xhr();
						if (myXhr.upload) { // if upload property exists
							myXhr.upload.addEventListener('progress',
									progressHandlingFunction, false); // progressbar
						}
						return myXhr;

					},
					success : function(data) {
			               if(data.success == 0 )
			               {
			            	
			            	   $.messager.alert("提示","添加加成功");
			            	 /*   $('#dg').datagrid('uncheckAll');
		                        $('#dg').datagrid('reload'); */
		                        //$("#dlgwindow").dialog('close');
		                     parent.location.reload();
		                        fun_ret = true;
			                  
			               }
			               else
			               {
			            	   $.messager.alert("提示","添加加成功");
			               }
			           },
					error : errorHandler = function(data) {
						$.messager.alert("错误提示", data.msg);
						return false;
					}
				});	
	
 return fun_ret; 
	}
	function progressHandlingFunction(e) {
		if (e.lengthComputable) {
			$('progress').attr({
				value : e.loaded,
				max : e.total
			});
		}
	}
	
</script>
<style type="text/css">
#formModule table td input{
	width:180px;
	height:25px;
}


</style>
</head>
<body>
   <div id="dlg-buttons">     
        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="btnSave_click()">保存</a>  
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close')">关闭</a>  
  </div> 
    <br>
	<div style="padding: 1px" align="center">
		<form id="formModule" method="post">
		 <c:if test="${!empty model.id}">
			<input id="id" type="hidden" name="id" value="${model.id }">
			<input id="id" type="hidden" name="status "value="${model.status }">
			
			<input id="id" type="hidden" name="picture" value="${model.picture }">
			</c:if>
           <%--  <input id="photo" type="hidden" name="photo" value="${model.photo }"> --%>
			<table border="0">
			
				<tr height="30">
					<td>商品名称：</td>
					<td><input id="name" maxlength="10" placeholder="请输入用户名称"
						class="easyui-validatebox textbox" type="text" style="width: 180px;height: 25px "
						name="name" data-options="required:true"
						 value="${model.name }"></input></td>
				</tr>
				<tr height="30">
					<td>商品价格：</td>
					<td><input id="LOGINNAME" maxlength="11" placeholder="请输入"
						class="easyui-validatebox textbox" type="text" 
						name="price" style="width: 180px;height: 25px " value="${model.price }"></input></td>
				</tr>
				
				<tr height="30">
					<td>库存：</td>
					<td><input id="LOGINNAME" maxlength="11" placeholder="库存"
						class="easyui-validatebox textbox" type="text" 
						name="inventoryNum" style="width: 180px;height: 25px " value="${model.inventoryNum }"></input></td>
				</tr>
				<tr height="30">
					<td>鞋码：</td>
					<td><input id="LOGINNAME" maxlength="50" placeholder="多个鞋码用逗号隔开"
						class="easyui-validatebox textbox" type="text" 
						name="shoeSize" style="width: 180px;height: 25px " value="${model.shoeSize }"></input></td>
				</tr>
				
				<tr height="30">
				<td>商品的地址：</td>
                    <td><input id="password" 
                    class="easyui-validatebox textbox" maxlength="1000"
                    type="text" name="address"  style="width: 180px;height: 25px "  value="${model.address }"></input></td>
                </tr>
                	<%-- <tr height="30">
				   <td>地址：</td>
                    <td><input id="address" 
                    class="easyui-validatebox textbox" maxlength="16"
                    type="text" name="address"    value="${model.address }"></input></td>
                </tr> --%>
			    
				 <tr height="30">
					<td>商品的分类：</td>
					<td><select id="ppp" class="easyui-combotree"
					 url="http://localhost:8080/shoeHouse/commodifyCategory/treeView" 
					 name="categoryId" style="width:156px; ">
					<option value="${model.categoryId }" <c:if test="${!empty model.categoryId}">selected</c:if>></option>
					</select>
					</td>
				</tr>
				<tr height="30">
				   <td>商品的内容：</td>
                    <td>
                    <input id="password" 
                    class="easyui-validatebox textbox" maxlength="1000"
                    type="text" name="account"  style="width: 180px;height: 25px "  value="${model.account }"></input>
                    
                   </td>
                </tr>
				  <tr height="30">
                    <td>商品的图片：</td>
                    <td><input type="file" class="easyui-linkbutton"
						data-options="toggle:true,group:'g2',plain:true"
						 id="uploadFile"
						name="uploadFile" style="width: 200px;" /></td>
                </tr>	
                
                <c:if test="${!empty model.picture}">
                 <tr height="30">
                    <td>商品的图片：</td>
				<td><img src="${model.picture}" width="100" height="100" /></td>
			</tr>
			</c:if>
			
			<tr height="30">
				   <td>商品的描述：</td>
                    <td>
                    <textarea rows="10" cols="30" style="width: 180px;height:50px "
                name="commodifyDexc">${model.commodifyDexc }</textarea>
                    
                   </td>
                </tr>
			</table>
		</form>
	</div>
	
</body>
</html> 
